package com.samehope.ar.controller;

import com.samehope.ar.common.CommonResult;
import com.samehope.ar.constant.FileTypeEnum;
import com.samehope.ar.util.CosUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


/**
 * <p>
 * 上传腾讯云 对象存储
 * </p>
 *
 * @author LD
 * @since 2020-1-15
 */
@RestController
@RequestMapping("/cos")
public class COSController {

    /**
     * 上传图片
     * @param file
     * @return
     */
    @RequestMapping(value = "/uploadPic")
    public CommonResult uploadPic(@RequestParam("file")MultipartFile file) {
        return CosUtils.upload(file, FileTypeEnum.PIC.getCode());
    }

    /**
     * 上传视频
     * @param file
     * @return
     */
    @RequestMapping(value = "/uploadVideo")
    public CommonResult uploadVideo(@RequestParam("file")MultipartFile file){
        return CosUtils.upload(file, FileTypeEnum.VIDEO.getCode());
    }

    @RequestMapping(value = "/getCredential")
    public CommonResult getCredential(){
        return CommonResult.success(CosUtils.getCredential());
    }
}
